//
//  CLThreadViewController.m
//  Charles
//
//  Created by Charles on 2017/4/16.
//  Copyright © 2017年 charles. All rights reserved.
//

#import "CLThreadViewController.h"
#import "CLThreadContainerViewController.h"
@interface CLThreadViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (strong,nonatomic) UITableView *tableView;
@property (strong,nonatomic) NSArray *titles;

@end

@implementation CLThreadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.titles = @[@"GCD",@"RunLoop",@"NSOperation",@"NSThread&pthread"];
}

#pragma mark - UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titles.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    CLThreadContainerViewController *containerView = [[CLThreadContainerViewController alloc]init];
    CLThreadType type = indexPath.row + 1;
    containerView.type = type;
    [self.navigationController pushViewController:containerView animated:YES];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *strId = @"id";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strId];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strId];
    }
    if (indexPath.row < self.titles.count) {
        cell.textLabel.text = self.titles[indexPath.row];
    }
    return cell;
}

- (UITableView *)tableView {
    if (nil == _tableView) {
        _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        [self.view addSubview:_tableView];
    }
    return _tableView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
